<?php

namespace Frieza\Modules\AbTest\Actions;

use Encore\Admin\Actions\RowAction;
use Doraemon\model\AbTest\AbTestGroupInfo as mAbTestGroupInfo;
use Doraemon\model\AbTest\AbTestBasicInfo as mAbTestBasicInfo;

class Release extends RowAction
{
    public $name = '关闭实验';

    public function form()
    {
        $groupInfo = mAbTestGroupInfo::select(['group_id', 'title'], ['test_id' => $this->row('test_id'), 'group_status[!]' => mAbTestGroupInfo::DELETE_STATUS]);
        $testInfo = mAbTestBasicInfo::getInfoByTestId($this->row('test_id'));
        if($groupInfo) {
            $option = [];
            foreach($groupInfo as $info) {
                $option[$info['group_id']] = $info['title'];
            }

            $this->select('group_id', "{$testInfo['title']}  切全量到")->options($option)->default(array_shift(array_keys($option)));
            $this->text('result_url', '实验分析文档')->value($testInfo['result_url'])->required();
            $this->hidden('test_id')->value($this->row('test_id'));
        }

    }

    public function getHandleRoute()
    {
        return admin_url('abTest/release');
    }
}